Skip to content

feat: optional session store (resumabillity support)#775

Open
glicht wants to merge 7 commits intomodelcontextprotocol:mainfrom
binahm:feat/session-store
Open

feat: optional session store (resumabillity support)#775
glicht wants to merge 7 commits intomodelcontextprotocol:mainfrom
binahm:feat/session-store

Conversation

@glicht
Copy link
Copy Markdown
Contributor

@glicht glicht commented Mar 25, 2026

Motivation and Context

In horizontally-scaled deployments or after restarting a server, MCP clients use Mcp-Session-Id to resume sessions. When routed to a different server instance or after a restart, the session is unknown and clients get a 404, forcing re-initialization.

This PR adds an optional SessionStore trait that persists InitializeRequestParams after a successful handshake. When a request arrives at an instance without a matching in-memory session, the store is consulted and the session is transparently restored by replaying initialize.

The SessionManager trait gains a restore_session method with a default no-op implementation. Custom session manager implementations can override it to integrate with their own logic if needed. The built-in LocalSessionManager has an implementation that re-creates the in-memory session worker.

Additionally to provide indication to ServerHandler implementation that a call to initialize and on_initialized is as a result of a restore, a marker SessionRestoreMarker is added to the context.extensions so implementors can act appropriately when a session is restored.

The feature is opt-in. Configurations without a session_store configured are unaffected.

Note: for full resumability and multi-server (behind a load balancer) support there is need to also implement an Event store so events aren't lost. This is being discussed at: #330

How Has This Been Tested?

Added a new integration test suite at: test_streamable_http_session_store.rs with three test scenarios.

Breaking Changes

None. Existing logic remains if session_store is not configured (defaults to None).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • [ x I have added or updated documentation as needed

Additional context

Related to #330

@glicht glicht requested a review from a team as a code owner March 25, 2026 15:43
@github-actions github-actions bot added T-dependencies Dependencies related changes T-test Testing related changes T-config Configuration file changes T-core Core library changes T-transport Transport layer changes labels Mar 25, 2026
@glicht glicht force-pushed the feat/session-store branch from e1f4999 to 192faa2 Compare March 30, 2026 18:14
@glicht glicht force-pushed the feat/session-store branch from 192faa2 to 2361eca Compare March 30, 2026 18:27
@glicht
Copy link
Copy Markdown
Contributor Author

glicht commented Apr 6, 2026

@alexhancock any feedback on this PR? Would really like to progress this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-dependencies Dependencies related changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants